package com.jili.single;

/**
 * ClassName: DependecyDemo
 * Package com.jili.single
 * Description:
 *
 * @Author: 廖继礼
 * @Create: 2024/7/27
 * @Version: v1.0
 */
public class DependecyDemo {
    public static void main(String[] args) {
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

class Email implements Receiver{
    public String getInfo(){
        return "电子邮件信息";
    }
}

class WeiXin implements Receiver{
    public String getInfo(){
        return "微信消息";
    }
}

class Person{

    // 如果我们要获取的对象是微信、短信，则新增类，同是person也要增加相应的接收方法。
    // 解决思路：引入一个车抽象的接口IReceiver，表示接收者，这样Person类与接口Receiver发生依赖
    public void receive(Receiver receiver){
        System.out.println(receiver.getInfo());
    }
}
